package com.amarsoft.are.log.impl;

import com.amarsoft.are.log.impl.FileHandler;
import com.amarsoft.are.log.impl.simple.Formatter;
import com.amarsoft.are.log.impl.simple.LogRecord;

public class DataInterfaceFileHandler extends FileHandler{

	 public void configure()
	  {
	    super.configure();
	    String systemPrefix = "com.amarsoft.are.log.impl.DataInterfaceFileHandler.";
	    String lvl = getStringProperty(systemPrefix + "level");
	    if (lvl != null) {
	      setLogLevel(lvl);
	    }
	    
	    setPattern(getStringProperty(systemPrefix + "pattern", "./log/datainterface_%g.log"));
	    setLimit(getStringProperty(systemPrefix + "limit", "1024000"));
	    setCount(getStringProperty(systemPrefix + "count", "10"));
	    setAppend(getStringProperty(systemPrefix + "append", "true"));
	    

	    String formatVal = getStringProperty(systemPrefix + "formatter");
	    if (formatVal != null) {
	      try
	      {
	        Class<?> clz = Thread.currentThread().getContextClassLoader().loadClass(formatVal);
	        setFormatter((Formatter)clz.newInstance());
	      }
	      catch (Exception ex)
	      {
	        System.err.println("setFormatter Error:" + ex.getMessage());
	      }
	    }
	  }
	 
	  public void publish(LogRecord record)
	  {
		if(!"com.amarsoft.are.log.impl.DataInterfaceFileHandler".equals(record.getLoggerName())) return;
		
//	    Formatter f = getFormatter();
//	    if (f == null) {
	      publish(record.getMessage());
//	    } else {
//	      publish(f.format(record));
//	    }
	  }
	 
}